package de.rubaff.reqiengi.objects;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;


public class Requirement implements IId
{
	private int id;
	private String name;	
	private String text;	
	private float degreeOfFulfilment;	
	private Date endDate;	
	private List<Task> tasks;
	
	
	public Requirement() {
		this.name = "Default";
		this.text = "My first requirement with google guice";
		this.endDate = new Date();
		
	}

		
	public int getId()
	{
		return id;
	}
	
	public void setId(int id)
	{
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getText() {
		return text;
	}

	public void setText(String text) {
		this.text = text;
	}

	public float getDegreeOfFulfilment() {
		
		if(this.tasks == null || this.tasks.isEmpty())
			return (this.degreeOfFulfilment = 100.0f);
		
		int count = 0;
		
		for(Task task : this.tasks)
		{
			if(task.isState())
				count++;
		}
		if(count < 1)
			return (this.degreeOfFulfilment = 0.0f);
		
		return (this.degreeOfFulfilment = (float)count / (float)this.tasks.size() * 100);
	}

	public void setDegreeOfFulfilment(float degreeOfFulfilment) {
		this.degreeOfFulfilment = degreeOfFulfilment;
	}

	public Date getEndDate() {
		return endDate;
	}

	public void setEndDate(Date endDate) {
		this.endDate = endDate;
	}

	public List<Task> getTasks() {
		return tasks;
	}

	public void setTasks(List<Task> tasks) {
		this.tasks = tasks;
	}

	// Methoden
	
	public void addTask(Task task) {
		if (this.tasks == null) {
			this.tasks = new ArrayList<Task>();
		}
		this.tasks.add(task);
	}
	public void removeTask(Task task) {
		if (this.tasks != null) {
			this.tasks.remove(task);
		}
	}
	
}
